package com.cl.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.cl.safe.R;
import com.cl.service.AutoCleanprocessService;
import com.cl.utils.ServiceUtils;

public class TaskSettingActivity extends Activity {
	protected static final String TAG = "TaskSettingActivity";
	private SharedPreferences sp;
	private CheckBox cb_show_system;
	private CheckBox cb_auto_clean;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_task_setting);
		cb_show_system = (CheckBox) findViewById(R.id.cb_show_system);
		cb_auto_clean = (CheckBox) findViewById(R.id.cb_auto_clean);
		sp = getSharedPreferences("config", MODE_PRIVATE);
		boolean isUserTaskShow = sp.getBoolean("isUserTaskShow", false);
		cb_show_system.setChecked(isUserTaskShow);
		cb_show_system.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
					Editor editor = sp.edit();
					editor.putBoolean("isUserTaskShow", isChecked);
					editor.commit();
				}
		});
		cb_auto_clean.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if(isChecked) {
					Log.i(TAG, "开启锁屏自动清理进程服务");
					Intent service = new Intent(TaskSettingActivity.this,AutoCleanprocessService.class);
					startService(service);
				}else {
					Log.i(TAG, "关闭锁屏自动清理进程服务");
					Intent service = new Intent(TaskSettingActivity.this,AutoCleanprocessService.class);
					startService(service);
				}
				
			}
		});
	}
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		boolean result = ServiceUtils.isRuningServer(this, "com.itheima.service.AutoCleanprocessService");
		cb_auto_clean.setChecked(result);
	
	}

}
